﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Text.RegularExpressions;

namespace HZ.DrugTrade.DAL
{
    public class Search_Util
    {
        public static string GetModelQuery(string medicineModel)
        {
            Regex regex = new Regex(@"剂$");

            medicineModel = regex.Replace(medicineModel, "");

            return string.Format(" AND MedicineModelName LIKE '%{0}%'", medicineModel);
            //Regex reg = new Regex("粉针|溶酶结晶|冻干粉针");
            //Match m = reg.Match(medicineModel);
            //if (m.Success)
            //{

            //}


             
        }
        /// <summary>
        /// 规格采用关键字处理
        /// </summary>
        /// <param name="Outlookc"></param>
        /// <returns></returns>
        public static string GetOutlookc(string Outlookc)
        {
            Outlookc = HZ.Common.zhHansUtil.ConvertToDBC(Outlookc);
            StringBuilder where = new StringBuilder();
            Regex num = new Regex(@"\d+(\.\d+)?");
            Match m = num.Match(Outlookc);
            if (m.Success)
            {
                double d = double.Parse(m.Value);

                where.AppendFormat(" AND (GetOutlookcNum(Outlookc) = {0}", m.Value);
                if (d <= 0.1)
                {
                    where.AppendFormat(" OR GetOutlookcNum(Outlookc) = {0}", d * 1000);
                }
                if (d >= 100)
                {
                    where.AppendFormat(" OR GetOutlookcNum(Outlookc) = {0}", d / 1000);
                }

                where.Append(")");
            }

            Regex pack = new Regex(@"塑瓶|玻瓶|[\u4e00-\u9fa5]+软袋");

            Match m2 = pack.Match(Outlookc);
            if (m2.Success)
            {
                where.AppendFormat(" AND Outlookc LIKE '%{0}%'", m2.Value);

            }
            return where.ToString();

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pack"></param>
        /// <returns></returns>
        public static string GetFactor(string pack)
        {
            pack = HZ.Common.zhHansUtil.ConvertToDBC(pack);
            Regex regex = new Regex(@"\d+");
            MatchCollection mc = regex.Matches(pack);
            if (mc.Count > 0)
            {
                Match m = mc[mc.Count - 1];
                return string.Format(" AND Factor = {0}", m.Value);
            }

            return "";
        }
        /// <summary>
        /// 处理生产企业生产企业采用相似度处理
        /// </summary>
        /// <param name="CompanyName_SC"></param>
        /// <returns></returns>
        public static string GetCompanyName_SC(string CompanyName_SC)
        {
            Regex split = new Regex("省"); //替换省市
            Regex replace2 = new Regex("有限|责任|公司|股份|制药|医药|生物|科技");
            string s = replace2.Replace(CompanyName_SC, "").Replace("省", "");

            Regex gg = new Regex("上海|北京|广东|江苏|浙江|山东|四川|天津|重庆|辽宁|云南|河南|河北|福建|安徽|湖北|黑龙江|江西|吉林|陕西|湖南|山西|甘肃|内蒙古|广西|贵州|新疆|海南|宁夏|西藏|青海", RegexOptions.IgnoreCase);

            Match m = gg.Match(s);
            string result = string.Empty;
            if (m.Success)
            {
                result += string.Format(" AND CompanyName_SC LIKE '{0}%'", m.Value);
                result += string.Format(" AND CompanyName_SC LIKE '%{0}%'", s.Replace(m.Value, ""));
                return result;
            }
            else
                return string.Format(" AND CompanyName_SC LIKE '%{0}%'", s);

        }
    }
}
